
/*
 * @Author: jlgit jlgit@itcode.cn
 * @Date: 2023-09-14 09:16:40
 * @LastEditors: jlgit jlgit@itcode.cn
 * @LastEditTime: 2023-09-14 14:34:41
 * @FilePath: \jl-shopping\src\utils\storage.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE=>
 */
const INFO_KEY = 'hm_shopping_info'
const HISTORY_VALUE = 'hm_history_list'
// 获取个人信息
export const getInfo = () => {
  const defaultObj = { token: '', userId: '' }
  const result = localStorage.getItem(INFO_KEY)
  return result ? JSON.parse(result) : defaultObj
}
// 设置个人信息

export const setInfo = (obj) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(obj))
}
// 移除个人信息

export const removeInfo = (obj) => {
  localStorage.removeItem(INFO_KEY)
}
// 获取搜索历史
export const getHistoryList = () => {
  const result = localStorage.getItem(HISTORY_VALUE)
  return result ? JSON.parse(result) : []
}
// 设置搜索历史
export const setHistoryList = (arr) => {
  localStorage.setItem(HISTORY_VALUE, JSON.stringify(arr))
}
